package com.gdk.ksoft.ui.reporters.adapters;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.gdk.ksoft.R;
import com.gdk.ksoft.assembly.utils.extensions.FormatUtils;

import java.util.HashMap;
import java.util.List;

/**
 * Created by hel on 2014-12-09.
 * 订单日报表数据适配器
 */
public class OrderStatementAdapter extends BaseAdapter {

    private Context context;
    private List<HashMap<String,Object>> lst;

    public OrderStatementAdapter(Context context,List<HashMap<String,Object>> lst) {
        this.context = context;
        this.lst = lst;
    }

    @Override
    public int getCount() {
        return lst == null?0:lst.size();
    }

    @Override
    public Object getItem(int position) {
        return lst.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final HashMap<String,Object> item = lst.get(position);
        ViewHolder holder = null;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = View.inflate(context, R.layout.item_porderstatement_lststatement,null);
            holder.txtIcon = (TextView)convertView.findViewById(R.id.item_porderstatement_lststatement_txtIcon);
            holder.txtCustomerName = (TextView)convertView.findViewById(R.id.item_porderStatement_lststatement_txtCustomerName);
            holder.txtCustomerAddr = (TextView)convertView.findViewById(R.id.item_porderStatement_lststatement_txtCustomerAddr);
            holder.txtOrderNo = (TextView)convertView.findViewById(R.id.item_porderStatement_lststatement_txtOrderNo);
            holder.txtTotalCounter = (TextView)convertView.findViewById(R.id.item_porderStatement_lststatement_txtCount);
            holder.txtTotalMoney = (TextView)convertView.findViewById(R.id.item_porderStatement_lststatement_txtMoney);
            holder.imgDjbz = (ImageView)convertView.findViewById(R.id.item_porderStatement_lststatement_imgDjbz);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder)convertView.getTag();
        }
        holder.txtIcon.setText(item.get("kico").toString());
        holder.txtCustomerName.setText(item.get("kmc").toString());
        holder.txtCustomerAddr.setText("地址："+item.get("kaddr").toString());
        holder.txtOrderNo.setText("单号："+item.get("xdjh"));
        holder.txtTotalCounter.setText("数量：" + item.get("xssl") + item.get("xsdw") + item.get("xsss") + item.get("hsdw"));
        holder.txtTotalMoney.setText("金额："+ FormatUtils.exactNumber(item.get("xssy"),"0.00")+"元");
        boolean isVisiable = Integer.parseInt(item.get("djbz").toString()) == 0;//是否可见
        holder.imgDjbz.setVisibility(isVisiable?View.VISIBLE:View.GONE);
        holder.imgDjbz.setBackgroundColor(isVisiable? Color.GREEN:Color.TRANSPARENT);
        return convertView;
    }

    class ViewHolder{
        public TextView txtIcon;
        public ImageView imgDjbz;
        public TextView txtCustomerName;
        public TextView txtCustomerAddr;
        public TextView txtOrderNo;
        public TextView txtTotalCounter;
        public TextView txtTotalMoney;
    }

}
